package com.gqqx.common.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 通用返回结果类
 */
@Data
@ApiModel(value = "全局统一返回结果")
public class Rt<T> {

    @ApiModelProperty(value = "返回码")
    private Integer success;//1:成功  2:失败

    @ApiModelProperty(value = "气象站编号")
    private T station;//气象站编号

    @ApiModelProperty(value = "返回数据")
    private T data;//数据

    @ApiModelProperty(value = "返回Id")
    private Long id;//返回用户id

    @ApiModelProperty(value = "返回时间")
    private T date;//返回用户id

    @ApiModelProperty(value = "返回错误信息")
    private String msg;//错误信息

    /**
     * 成功时返回1
     * @return
     * @param <T>
     */
    public static <T> Rt<T> success(){
        Rt<T> rt = new Rt<>();
        rt.success = 1;
        return rt;
    }
    /**
     * 成功返回1和用户id
     */
    public static <T> Rt<T> success(Long id){
        Rt<T> rt = new Rt<>();
        rt.success = 1;
        rt.id = id;
        return rt;
    }
    /**
     * 成功返回1和数据和气象编号
     * @param data
     * @param station
     * @param <T>
     * @return
     */
    public static <T> Rt<T> success(T data,T station){
        Rt<T> rt = new Rt<>();
        rt.data = data;
        rt.success = 1;
        rt.station = station;
        return rt;
    }
    /**
     * 成功返回1和数据和气象编号
     * @param data
     * @param station
     * @param <T>
     * @return
     */
    public static <T> Rt<T> success(T data,T station,T date){
        Rt<T> rt = new Rt<>();
        rt.data = data;
        rt.success = 1;
        rt.station = station;
        rt.date = date;
        return rt;
    }

    /**
     * 成功返回1和气象编号
     * @param station
     * @param <T>
     * @return
     */
    public static <T> Rt<T> success(T station){
        Rt<T> rt = new Rt<>();
        rt.success = 1;
        rt.station = station;
        return rt;
    }



    /**
     * 失败时返回0
     * @return
     * @param <T>
     */
    public static <T> Rt<T> error(){
        Rt rt = new Rt();
        rt.success = 0;
        return rt;
    }
    /**
     * 失败时返回0和错误信息
     * @return
     * @param <T>
     */
    public static <T> Rt<T> error(String msg){
        Rt rt = new Rt();
        rt.success = 0;
        rt.msg = msg;
        return rt;
    }
}
